﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;
using BssDs.Client.UI.Controls.ExtendedControl.Tab;
using System.Diagnostics;

namespace BssDs.Client.UI.Screens.MainWindow
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class Main : RibbonWindow
	{
		public Main()
		{
			InitializeComponent();

			// Insert code required on object creation below this point.
		}


		private void tabControl1_NewTabItemAdded(object sender, RoutedEventArgs e)
		{
			DefaultPage defaultPage = new DefaultPage();

			this.ShowPage("空のページ", defaultPage);

			Debug.Print(MainTabControl.SelectedIndex.ToString());
		}


		public void ShowPage(string header, Page tabPage)
		{
			Frame frame = new Frame();
			frame.NavigationUIVisibility = NavigationUIVisibility.Visible;
			frame.NavigationService.Navigate(tabPage);

			Grid grid = new Grid();
			grid.Children.Add(frame);

			int index = MainTabControl.GetNewTabItemAddedPosition();

			TabItemEx tabItemEx = MainTabControl.Items[index] as TabItemEx;
			if (tabItemEx != null)
			{
				tabItemEx.Title = header;
				tabItemEx.Content = grid;
			}
			else
			{
				TabItem tabItem = MainTabControl.Items[index] as TabItem;
				tabItem.Header = header;
				tabItem.Content = grid;
			}
		}
	}
}
